package com.ztz.mynewdemo.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import com.avos.avoscloud.AVObject;
import com.ztz.mynewdemo.R;
import com.ztz.mynewdemo.activity.DynamicDetailActivity;
import com.ztz.mynewdemo.activity.ZhanKuActivity;

import java.text.SimpleDateFormat;
import java.util.List;

/**
 * Created by wqewqe on 2018/1/9.
 */

public class DynamicAdapter extends CommonRecyclerAdapter<AVObject> {
    Context context;

    public DynamicAdapter(Context mContext, List<AVObject> mDatas, int mLayoutId) {
        super(mContext, mDatas, mLayoutId);
        context = mContext;
    }

    @Override
    public void convert(ViewHolder holder, final AVObject items) {
        holder.setText(R.id.name_item_main, items.getAVUser("owner") == null ? "" : items.getAVUser("owner").getUsername());
        holder.setText(R.id.title_item_main, items.getString("title") == null ? "" : items.getString("title"));
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String date = dateFormat.format(items.getUpdatedAt());
        String contentUrl = items.getString("contentUrl");
        holder.setText(R.id.dy_time, date);
        holder.setImageUrl(R.id.picture_item_main, items.getAVFile("image") == null ? "" : items.getAVFile("image").getUrl());
        holder.setOnItemClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, DynamicDetailActivity.class);
                intent.putExtra(DynamicDetailActivity.OBJECT_ID, items.getObjectId());
                context.startActivity(intent);
            }
        });
        holder.setOnClickListener(R.id.title_item_main, v -> {
            Intent intentTitle = new Intent(context, ZhanKuActivity.class);
            intentTitle.putExtra(ZhanKuActivity.CONTENTURL,contentUrl);
            context.startActivity(intentTitle);
        });
    }
}
